package com.ziyueyuwen.xiniao.controller.product.stage;

import com.suyeer.basic.util.HttpResUtil;
import com.ziyueyuwen.xiniao.base.HttpResContent;
import com.ziyueyuwen.xiniao.bean.ZyProductStage;
import com.ziyueyuwen.xiniao.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.List;

import static com.ziyueyuwen.xiniao.base.BaseUtil.saveErrorMsgAndData;
import static com.ziyueyuwen.xiniao.base.BaseUtil.saveSuccessMsgAndData;

/**
 * @author wancheng  on 2019/2/22.
 */
@Controller
@RequestMapping("/product/stage")
@Validated
public class ProductStageController {

    @Autowired
    ProductService productService;

    @RequestMapping(value = "/get_product_stage.do", method = RequestMethod.POST)
    public void upperOrLowerShelf(HttpServletRequest request,
                                  HttpServletResponse response) {
        HttpResContent<List<ZyProductStage>> hrc = new HttpResContent<>(request, response);
        hrc.setFuncDes("获取商品的期次");
        try {
            saveSuccessMsgAndData(hrc, productService.getProductStage());
        } catch (Exception e) {
            e.printStackTrace();
            saveErrorMsgAndData(hrc, e);
        } finally {
            HttpResUtil.writeResult(hrc, true);
        }
    }
}
